package com.company;
import java.util.Arrays;
import java.util.Date;
import java.io.File;

public class FileTest {
    public static void main(String[] args)throws Exception {
           String filePath = "D:/MyFolder";
           String fileName = "test.txt";
           File myFolder = new File(filePath);
           if(!myFolder.exists()){
               myFolder.mkdir();
           }

           File myFile = new File(filePath+"/"+fileName);
           if(!myFile.exists){
               myFile.createNewFile();
           }
        System.out.println("--------------------------------");

        System.out.println("文件绝对路径:"+myFile.getAbsolutePath());
        System.out.println("文件名称:"+myFile.getName());
        System.out.println("文件父节点:"+myFile.getParent());
        System.out.println("是文件夹吗？:"+myFile.isDirectory());
        System.out.println("是文件吗？:"+myFile.isFile());
        System.out.println("是隐藏的吗？:"+myFile.isHidden());
        System.out.println("是可读的吗？:"+myFile.canRead());
        System.out.println("是可写的吗？:"+myFile.canWrite());
        System.out.println("是可执行的吗？:"+myFile.canExecute());
        System.out.println("文件的大小:"+myFile.length() +"字节");
        System.out.println("------------------------");
        File[]allFilePath = myFolder.listFiles();
        System.out.println("文件：");
        for (File file:files){
            if(file.isFile()){
                System.out.println("\t"+file.getName);
            }
        }
        System.out.println("文件夹：");
        for(File file:files){
            if (file.isDirectory()){
                System.out.println("\t"+file.getName());
            }
        }
        File[]roots = File.listRoots();
        for(int i =0;i<roots.length;i++){
            System.out.println(roots[i]);
            System.out.println("空闲空间"+roots[i].getFreeSpace());
            System.out.println("可用空间"+roots[i].getUsableSpace());
            System.out.println("总空间"+roots[i].getTotalSpace());
            System.out.println();
        }
        System.out.println("-----------------------------");

        myFile.delete();
        if(!myFile.exists()){
            System.out.println("文件删除成功");
        }
        myFolder.delete();
        if (!myFolder.exists()){
            System.out.println("文件夹删除成功");
        }
        System.out.println("----------------------");

    }
}
